Load all required libraries.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(broom)
Read in raw data from RDS.
raw_data <- readRDS("./n1_n2_cleaned_cases.rds")
Make a few small modifications to names and data for visualizations.
final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
rename(Facility = wrf) %>%
mutate(Facility = recode(Facility,
"NO" = "WRF A",
"MI" = "WRF B",
"CC" = "WRF C"))
Seperate the data by gene target to ease layering in the final plot
#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>%
select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
group_by(date) %>% summarise_if(is.numeric, mean)
#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]
only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]
Build the main plot
#first layer is the background epidemic curve
p1 <- only_background %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~new_cases_clarke,
type = "bar",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Daily Cases: ', new_cases_clarke),
alpha = 0.5,
name = "Daily Reported Cases",
color = background_color,
colors = background_color,
showlegend = FALSE) %>%
layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#renders the main plot layer two as seven day moving average
p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke,
type = "scatter",
mode = "lines",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
name = "Seven Day Moving Average Athens",
line = list(color = seven_day_ave_color),
showlegend = FALSE)
#renders the main plot layer three as positive target hits
p2 <- plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n1,
symbol = ~Facility,
marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n2,
symbol = ~Facility,
marker = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(yaxis = list(title = "SARS CoV-2 Copies/L",
showline = TRUE,
type = "log",
dtick = 1,
automargin = TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#adds the limit of detection dashed line
p2 <- p2 %>% plotly::add_segments(x = as.Date("2020-03-14"),
xend = ~max(date + 10),
y = 3571.429, yend = 3571.429,
opacity = 0.35,
line = list(color = "black", dash = "dash")) %>%
layout(annotations = list(x = as.Date("2020-03-28"), y = 3.8, xref = "x", yref = "y",
text = "Limit of Detection", showarrow = FALSE))
p1
p2
Combine the two main plot pieces as a subplot
#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")
#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")
#rejoin the old data frames then seperate in to averages for each plant.
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)
Build loess smoothing figures figures
This makes the individual plots
#**************************************WRF A PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77',
span = 0.25, n = 898)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'
fit_botha
## [1] 13.01877 13.01516 13.01158 13.00803 13.00453 13.00106 12.99763 12.99424
## [9] 12.99088 12.98757 12.98429 12.98105 12.97786 12.97470 12.97158 12.96850
## [17] 12.96546 12.96247 12.95951 12.95660 12.95373 12.95089 12.94811 12.94536
## [25] 12.94266 12.94000 12.93738 12.93481 12.93228 12.92979 12.92735 12.92496
## [33] 12.92261 12.92030 12.91804 12.91583 12.91366 12.91154 12.90946 12.90743
## [41] 12.90545 12.90352 12.90163 12.89980 12.89801 12.89627 12.89457 12.89293
## [49] 12.89134 12.88980 12.88832 12.88692 12.88561 12.88437 12.88322 12.88213
## [57] 12.88112 12.88018 12.87932 12.87852 12.87779 12.87712 12.87652 12.87597
## [65] 12.87549 12.87507 12.87470 12.87439 12.87413 12.87393 12.87377 12.87366
## [73] 12.87360 12.87359 12.87361 12.87368 12.87379 12.87393 12.87412 12.87433
## [81] 12.87458 12.87487 12.87518 12.87552 12.87588 12.87627 12.87669 12.87712
## [89] 12.87758 12.87805 12.87854 12.87904 12.87955 12.88008 12.88062 12.88116
## [97] 12.88171 12.88226 12.88282 12.88345 12.88421 12.88510 12.88611 12.88725
## [105] 12.88849 12.88985 12.89131 12.89286 12.89450 12.89623 12.89805 12.89993
## [113] 12.90189 12.90391 12.90598 12.90811 12.91029 12.91251 12.91477 12.91706
## [121] 12.91938 12.92171 12.92406 12.92642 12.92879 12.93115 12.93351 12.93585
## [129] 12.93818 12.94048 12.94276 12.94500 12.94720 12.94935 12.95146 12.95351
## [137] 12.95550 12.95742 12.95927 12.96104 12.96360 12.96772 12.97324 12.98003
## [145] 12.98792 12.99678 13.00644 13.01677 13.02762 13.03883 13.05025 13.06174
## [153] 13.07315 13.08433 13.09513 13.10540 13.11499 13.12375 13.13154 13.13820
## [161] 13.14358 13.14755 13.14994 13.15175 13.15406 13.15682 13.15999 13.16352
## [169] 13.16738 13.17152 13.17589 13.18046 13.18518 13.19001 13.19491 13.19984
## [177] 13.20474 13.20959 13.21433 13.21892 13.22333 13.22751 13.23141 13.23499
## [185] 13.23822 13.24104 13.24342 13.24532 13.24668 13.24747 13.24765 13.24717
## [193] 13.24599 13.24406 13.24136 13.23782 13.23341 13.22809 13.22160 13.21376
## [201] 13.20468 13.19443 13.18311 13.17080 13.15759 13.14358 13.12886 13.11350
## [209] 13.09761 13.08127 13.06457 13.04759 13.03044 13.01319 12.99594 12.97878
## [217] 12.96179 12.94507 12.92870 12.91278 12.89739 12.88262 12.86856 12.85530
## [225] 12.84141 12.82553 12.80783 12.78849 12.76770 12.74563 12.72245 12.69836
## [233] 12.67353 12.64813 12.62236 12.59637 12.57037 12.54452 12.51900 12.49400
## [241] 12.46969 12.44625 12.42386 12.40271 12.38296 12.36480 12.34841 12.33290
## [249] 12.31727 12.30154 12.28573 12.26986 12.25394 12.23799 12.22204 12.20609
## [257] 12.19018 12.17431 12.15850 12.14278 12.12717 12.11167 12.09631 12.08111
## [265] 12.06609 12.05126 12.03664 12.02226 12.00812 11.99426 11.98068 11.96740
## [273] 11.95445 11.94205 11.93040 11.91945 11.90917 11.89949 11.89038 11.88180
## [281] 11.87370 11.86603 11.85876 11.85183 11.84520 11.83883 11.83268 11.82669
## [289] 11.82083 11.81505 11.80930 11.80355 11.79774 11.79184 11.78579 11.77955
## [297] 11.77309 11.76634 11.75928 11.75185 11.74402 11.73542 11.72583 11.71536
## [305] 11.70413 11.69225 11.67984 11.66702 11.65390 11.64061 11.62725 11.61395
## [313] 11.60082 11.58798 11.57555 11.56364 11.55237 11.54186 11.53222 11.52357
## [321] 11.51604 11.50972 11.50475 11.50124 11.49800 11.49384 11.48887 11.48319
## [329] 11.47690 11.47013 11.46296 11.45552 11.44790 11.44022 11.43257 11.42507
## [337] 11.41783 11.41095 11.40453 11.39869 11.39353 11.38915 11.38567 11.38319
## [345] 11.38182 11.38167 11.38284 11.38543 11.38956 11.39533 11.40297 11.41254
## [353] 11.42392 11.43698 11.45161 11.46767 11.48505 11.50361 11.52324 11.54381
## [361] 11.56520 11.58729 11.60994 11.63304 11.65646 11.68007 11.70376 11.72740
## [369] 11.75086 11.77403 11.79677 11.81897 11.84050 11.86123 11.88104 11.89981
## [377] 11.91742 11.93373 11.95113 11.97184 11.99555 12.02192 12.05063 12.08135
## [385] 12.11377 12.14754 12.18235 12.21787 12.25378 12.28973 12.32542 12.36052
## [393] 12.39469 12.42762 12.45897 12.48842 12.51564 12.54031 12.56211 12.58069
## [401] 12.59575 12.60892 12.62205 12.63511 12.64806 12.66089 12.67356 12.68604
## [409] 12.69830 12.71032 12.72206 12.73351 12.74462 12.75537 12.76573 12.77567
## [417] 12.78516 12.79418 12.80270 12.81068 12.81809 12.82492 12.83112 12.83668
## [425] 12.84156 12.84573 12.84916 12.85116 12.85116 12.84931 12.84578 12.84073
## [433] 12.83432 12.82671 12.81807 12.80854 12.79830 12.78751 12.77632 12.76490
## [441] 12.75340 12.74200 12.73085 12.72011 12.70994 12.70050 12.69196 12.68447
## [449] 12.67820 12.67331 12.66799 12.66043 12.65084 12.63938 12.62626 12.61165
## [457] 12.59575 12.57873 12.56079 12.54212 12.52288 12.50329 12.48351 12.46374
## [465] 12.44416 12.42496 12.40633 12.38845 12.37150 12.35568 12.34117 12.32815
## [473] 12.31682 12.30736 12.29995 12.29479 12.29081 12.28685 12.28293 12.27906
## [481] 12.27525 12.27153 12.26790 12.26437 12.26097 12.25770 12.25459 12.25164
## [489] 12.24887 12.24630 12.24394 12.24180 12.23990 12.23825 12.23687 12.23577
## [497] 12.23496 12.23447 12.23430 12.23447 12.23500 12.23589 12.23717 12.23884
## [505] 12.24194 12.24735 12.25493 12.26449 12.27586 12.28888 12.30338 12.31919
## [513] 12.33614 12.35406 12.37279 12.39214 12.41197 12.43208 12.45233 12.47252
## [521] 12.49251 12.51212 12.53118 12.54952 12.56697 12.58336 12.59853 12.61230
## [529] 12.62451 12.63498 12.64356 12.65006 12.65432 12.65617 12.65660 12.65670
## [537] 12.65648 12.65593 12.65508 12.65391 12.65244 12.65067 12.64860 12.64624
## [545] 12.64359 12.64066 12.63744 12.63395 12.63019 12.62617 12.62188 12.61733
## [553] 12.61254 12.60749 12.60219 12.59666 12.59089 12.58488 12.57865 12.57220
## [561] 12.56553 12.55864 12.55154 12.54424 12.53673 12.52903 12.52114 12.51192
## [569] 12.50038 12.48675 12.47123 12.45403 12.43538 12.41547 12.39454 12.37279
## [577] 12.35043 12.32767 12.30474 12.28185 12.25920 12.23702 12.21551 12.19489
## [585] 12.17538 12.15718 12.14052 12.12560 12.11263 12.10184 12.09128 12.07896
## [593] 12.06506 12.04972 12.03312 12.01541 11.99674 11.97729 11.95721 11.93667
## [601] 11.91581 11.89481 11.87381 11.85300 11.83251 11.81252 11.79318 11.77465
## [609] 11.75710 11.74069 11.72557 11.71190 11.69985 11.68957 11.68123 11.67499
## [617] 11.67010 11.66573 11.66186 11.65849 11.65559 11.65317 11.65121 11.64969
## [625] 11.64862 11.64797 11.64775 11.64793 11.64850 11.64946 11.65080 11.65251
## [633] 11.65456 11.65697 11.65970 11.66276 11.66613 11.66981 11.67377 11.67909
## [641] 11.68673 11.69651 11.70828 11.72186 11.73708 11.75377 11.77177 11.79090
## [649] 11.81101 11.83191 11.85344 11.87544 11.89772 11.92014 11.94251 11.96466
## [657] 11.98644 12.00767 12.02818 12.04780 12.06636 12.08370 12.09965 12.11404
## [665] 12.12670 12.13893 12.15211 12.16616 12.18099 12.19653 12.21270 12.22942
## [673] 12.24662 12.26420 12.28210 12.30023 12.31852 12.33689 12.35526 12.37354
## [681] 12.39167 12.40955 12.42712 12.44429 12.46099 12.47714 12.49265 12.50745
## [689] 12.52146 12.53460 12.54679 12.55795 12.56801 12.57725 12.58604 12.59439
## [697] 12.60234 12.60989 12.61709 12.62394 12.63048 12.63673 12.64270 12.64843
## [705] 12.65394 12.65925 12.66438 12.66936 12.67421 12.67895 12.68361 12.68821
## [713] 12.69277 12.69732 12.70189 12.70648 12.71113 12.71587 12.72070 12.72566
## [721] 12.73078 12.73588 12.74079 12.74551 12.75005 12.75442 12.75862 12.76265
## [729] 12.76653 12.77026 12.77385 12.77729 12.78060 12.78378 12.78684 12.78978
## [737] 12.79261 12.79533 12.79795 12.80048 12.80292 12.80528 12.80756 12.80977
## [745] 12.81176 12.81339 12.81467 12.81564 12.81631 12.81670 12.81683 12.81673
## [753] 12.81642 12.81591 12.81523 12.81439 12.81343 12.81236 12.81120 12.80998
## [761] 12.80870 12.80741 12.80611 12.80482 12.80358 12.80239 12.80129 12.80029
## [769] 12.79941 12.79867 12.79782 12.79661 12.79506 12.79321 12.79109 12.78874
## [777] 12.78617 12.78343 12.78054 12.77753 12.77444 12.77130 12.76814 12.76499
## [785] 12.76187 12.75883 12.75589 12.75309 12.75045 12.74801 12.74579 12.74384
## [793] 12.74217 12.74049 12.73849 12.73619 12.73363 12.73084 12.72785 12.72468
## [801] 12.72137 12.71794 12.71443 12.71086 12.70726 12.70367 12.70010 12.69660
## [809] 12.69319 12.68990 12.68675 12.68379 12.68104 12.67852 12.67627 12.67431
## [817] 12.67268 12.67141 12.67052 12.67005 12.67001 12.67020 12.67037 12.67054
## [825] 12.67070 12.67087 12.67105 12.67127 12.67151 12.67179 12.67213 12.67252
## [833] 12.67298 12.67351 12.67412 12.67483 12.67563 12.67655 12.67757 12.67873
## [841] 12.68001 12.68144 12.68301 12.68474 12.68664 12.68871 12.69097 12.69334
## [849] 12.69576 12.69823 12.70077 12.70337 12.70603 12.70877 12.71158 12.71447
## [857] 12.71745 12.72052 12.72367 12.72693 12.73029 12.73375 12.73732 12.74101
## [865] 12.74482 12.74875 12.75280 12.75699 12.76131 12.76578 12.77039 12.77514
## [873] 12.78003 12.78506 12.79023 12.79554 12.80098 12.80654 12.81224 12.81806
## [881] 12.82401 12.83008 12.83627 12.84257 12.84899 12.85552 12.86217 12.86892
## [889] 12.87577 12.88273 12.88980 12.89696 12.90422 12.91157 12.91901 12.92655
## [897] 12.93417 12.94188
#assign fits to a vector
both_trenda <- fit_botha
#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax
#reassign dataframes (just to be safe)
work_botha <- wrfa_both
#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date
#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
data = smooth_frame_botha,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha,
'</br> Median Log Copies: ', round(both_trenda, digits = 2)),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(both_ymina, digits = 2)),
name = "",
fillcolor = '#1B9E77',
line = list(color = '#1B9E77')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF A") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfa_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65))
p_wrf_a
save(p_wrf_a, file = "./plotly_objs/p_wrf_a.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02',
span = 0.25, n = 898)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'
fit_bothb
## [1] 12.55368 12.55185 12.55006 12.54832 12.54663 12.54499 12.54340 12.54187
## [9] 12.54038 12.53894 12.53756 12.53623 12.53495 12.53372 12.53255 12.53144
## [17] 12.53038 12.52937 12.52842 12.52753 12.52669 12.52591 12.52519 12.52453
## [25] 12.52393 12.52339 12.52291 12.52248 12.52212 12.52182 12.52158 12.52141
## [33] 12.52130 12.52125 12.52126 12.52134 12.52149 12.52170 12.52198 12.52232
## [41] 12.52273 12.52321 12.52375 12.52437 12.52505 12.52580 12.52662 12.52752
## [49] 12.52848 12.52952 12.53065 12.53189 12.53325 12.53471 12.53628 12.53795
## [57] 12.53973 12.54160 12.54357 12.54563 12.54778 12.55001 12.55234 12.55474
## [65] 12.55722 12.55978 12.56242 12.56512 12.56789 12.57073 12.57364 12.57660
## [73] 12.57962 12.58270 12.58583 12.58901 12.59223 12.59550 12.59882 12.60217
## [81] 12.60556 12.60898 12.61243 12.61591 12.61942 12.62295 12.62650 12.63007
## [89] 12.63365 12.63725 12.64085 12.64447 12.64808 12.65170 12.65532 12.65894
## [97] 12.66254 12.66614 12.66973 12.67348 12.67756 12.68195 12.68663 12.69159
## [105] 12.69681 12.70226 12.70793 12.71381 12.71987 12.72609 12.73247 12.73897
## [113] 12.74559 12.75230 12.75908 12.76592 12.77281 12.77971 12.78662 12.79351
## [121] 12.80037 12.80718 12.81392 12.82057 12.82712 12.83354 12.83982 12.84595
## [129] 12.85189 12.85764 12.86318 12.86849 12.87354 12.87833 12.88283 12.88768
## [137] 12.89345 12.90006 12.90743 12.91547 12.92411 12.93325 12.94281 12.95271
## [145] 12.96286 12.97318 12.98358 12.99399 13.00431 13.01446 13.02436 13.03393
## [153] 13.04307 13.05171 13.05976 13.06714 13.07376 13.07954 13.08439 13.08824
## [161] 13.09099 13.09340 13.09627 13.09955 13.10321 13.10721 13.11150 13.11606
## [169] 13.12083 13.12579 13.13089 13.13610 13.14137 13.14667 13.15195 13.15719
## [177] 13.16234 13.16736 13.17222 13.17686 13.18127 13.18539 13.18919 13.19264
## [185] 13.19568 13.19828 13.20041 13.20203 13.20309 13.20356 13.20339 13.20256
## [193] 13.20102 13.19873 13.19565 13.19175 13.18699 13.18132 13.17404 13.16457
## [201] 13.15308 13.13973 13.12467 13.10807 13.09010 13.07091 13.05066 13.02953
## [209] 13.00767 12.98524 12.96241 12.93934 12.91619 12.89311 12.87029 12.84787
## [217] 12.82602 12.80490 12.78468 12.76551 12.74756 12.73098 12.71595 12.70263
## [225] 12.68942 12.67473 12.65869 12.64146 12.62316 12.60395 12.58396 12.56334
## [233] 12.54223 12.52077 12.49910 12.47737 12.45571 12.43427 12.41319 12.39261
## [241] 12.37267 12.35352 12.33529 12.31814 12.30219 12.28760 12.27450 12.26253
## [249] 12.25120 12.24046 12.23028 12.22060 12.21139 12.20259 12.19417 12.18609
## [257] 12.17830 12.17075 12.16340 12.15622 12.14915 12.14215 12.13518 12.12819
## [265] 12.12115 12.11400 12.10671 12.09923 12.09151 12.08352 12.07521 12.06654
## [273] 12.05746 12.04867 12.04085 12.03394 12.02786 12.02255 12.01795 12.01398
## [281] 12.01058 12.00767 12.00520 12.00309 12.00128 11.99970 11.99828 11.99696
## [289] 11.99566 11.99432 11.99288 11.99125 11.98939 11.98721 11.98466 11.98166
## [297] 11.97815 11.97406 11.96931 11.96386 11.95762 11.95024 11.94152 11.93159
## [305] 11.92060 11.90867 11.89596 11.88260 11.86874 11.85450 11.84004 11.82549
## [313] 11.81099 11.79668 11.78270 11.76919 11.75630 11.74415 11.73290 11.72267
## [321] 11.71362 11.70587 11.69958 11.69487 11.69025 11.68423 11.67695 11.66855
## [329] 11.65917 11.64896 11.63805 11.62661 11.61476 11.60265 11.59042 11.57822
## [337] 11.56620 11.55448 11.54322 11.53257 11.52265 11.51362 11.50563 11.49880
## [345] 11.49329 11.48924 11.48680 11.48610 11.48729 11.49052 11.49571 11.50266
## [353] 11.51124 11.52135 11.53289 11.54574 11.55980 11.57496 11.59111 11.60815
## [361] 11.62596 11.64443 11.66347 11.68296 11.70280 11.72287 11.74307 11.76329
## [369] 11.78343 11.80336 11.82300 11.84223 11.86094 11.87902 11.89636 11.91287
## [377] 11.92843 11.94292 11.95851 11.97722 11.99874 12.02277 12.04902 12.07718
## [385] 12.10697 12.13806 12.17018 12.20301 12.23626 12.26963 12.30281 12.33552
## [393] 12.36744 12.39828 12.42775 12.45553 12.48134 12.50486 12.52581 12.54388
## [401] 12.55877 12.57232 12.58649 12.60121 12.61638 12.63192 12.64774 12.66376
## [409] 12.67989 12.69604 12.71212 12.72805 12.74375 12.75912 12.77407 12.78853
## [417] 12.80241 12.81561 12.82805 12.83965 12.85032 12.85997 12.86851 12.87586
## [425] 12.88193 12.88664 12.88989 12.89120 12.89025 12.88723 12.88232 12.87571
## [433] 12.86759 12.85814 12.84754 12.83598 12.82365 12.81073 12.79742 12.78388
## [441] 12.77032 12.75691 12.74384 12.73130 12.71948 12.70855 12.69870 12.69013
## [449] 12.68301 12.67753 12.67163 12.66327 12.65264 12.63998 12.62547 12.60934
## [457] 12.59179 12.57304 12.55328 12.53274 12.51162 12.49013 12.46847 12.44687
## [465] 12.42553 12.40466 12.38446 12.36516 12.34695 12.33005 12.31466 12.30101
## [473] 12.28929 12.27971 12.27249 12.26784 12.26446 12.26094 12.25731 12.25360
## [481] 12.24985 12.24607 12.24231 12.23859 12.23493 12.23138 12.22797 12.22471
## [489] 12.22164 12.21880 12.21621 12.21390 12.21190 12.21024 12.20896 12.20808
## [497] 12.20763 12.20764 12.20814 12.20917 12.21075 12.21291 12.21568 12.21910
## [505] 12.22425 12.23208 12.24241 12.25504 12.26978 12.28644 12.30484 12.32477
## [513] 12.34605 12.36849 12.39190 12.41609 12.44086 12.46603 12.49141 12.51681
## [521] 12.54203 12.56688 12.59118 12.61474 12.63735 12.65884 12.67902 12.69768
## [529] 12.71465 12.72973 12.74273 12.75346 12.76172 12.76734 12.77181 12.77671
## [537] 12.78201 12.78764 12.79355 12.79970 12.80604 12.81250 12.81904 12.82562
## [545] 12.83216 12.83864 12.84499 12.85116 12.85710 12.86276 12.86809 12.87304
## [553] 12.87755 12.88158 12.88506 12.88796 12.89022 12.89179 12.89262 12.89265
## [561] 12.89183 12.89012 12.88746 12.88379 12.87908 12.87326 12.86629 12.85702
## [569] 12.84452 12.82908 12.81098 12.79052 12.76798 12.74364 12.71779 12.69072
## [577] 12.66271 12.63405 12.60503 12.57593 12.54703 12.51863 12.49101 12.46445
## [585] 12.43925 12.41568 12.39404 12.37461 12.35768 12.34352 12.32957 12.31319
## [593] 12.29459 12.27400 12.25162 12.22768 12.20239 12.17597 12.14864 12.12061
## [601] 12.09209 12.06332 12.03449 12.00583 11.97755 11.94988 11.92302 11.89720
## [609] 11.87263 11.84952 11.82810 11.80858 11.79118 11.77610 11.76358 11.75383
## [617] 11.74553 11.73727 11.72909 11.72102 11.71311 11.70539 11.69791 11.69070
## [625] 11.68381 11.67727 11.67112 11.66541 11.66017 11.65545 11.65127 11.64769
## [633] 11.64474 11.64246 11.64089 11.64007 11.64004 11.64084 11.64251 11.64588
## [641] 11.65164 11.65963 11.66968 11.68162 11.69529 11.71053 11.72717 11.74505
## [649] 11.76399 11.78384 11.80443 11.82560 11.84717 11.86899 11.89089 11.91271
## [657] 11.93427 11.95542 11.97598 11.99580 12.01471 12.03254 12.04913 12.06432
## [665] 12.07793 12.09148 12.10651 12.12290 12.14054 12.15933 12.17914 12.19986
## [673] 12.22138 12.24359 12.26637 12.28962 12.31321 12.33704 12.36100 12.38496
## [681] 12.40882 12.43246 12.45577 12.47865 12.50096 12.52261 12.54348 12.56346
## [689] 12.58242 12.60027 12.61689 12.63216 12.64597 12.65894 12.67176 12.68443
## [697] 12.69694 12.70929 12.72149 12.73352 12.74540 12.75710 12.76864 12.78002
## [705] 12.79122 12.80225 12.81310 12.82378 12.83428 12.84461 12.85475 12.86470
## [713] 12.87447 12.88406 12.89345 12.90265 12.91166 12.92048 12.92910 12.93752
## [721] 12.94574 12.95382 12.96182 12.96974 12.97755 12.98525 12.99281 13.00024
## [729] 13.00751 13.01462 13.02155 13.02829 13.03482 13.04114 13.04723 13.05308
## [737] 13.05867 13.06400 13.06905 13.07380 13.07826 13.08239 13.08620 13.08966
## [745] 13.09274 13.09541 13.09770 13.09961 13.10118 13.10242 13.10334 13.10398
## [753] 13.10435 13.10446 13.10434 13.10401 13.10348 13.10278 13.10193 13.10094
## [761] 13.09983 13.09863 13.09735 13.09601 13.09463 13.09323 13.09183 13.09046
## [769] 13.08912 13.08784 13.08616 13.08364 13.08037 13.07641 13.07183 13.06671
## [777] 13.06112 13.05512 13.04880 13.04221 13.03544 13.02855 13.02162 13.01472
## [785] 13.00792 13.00128 12.99489 12.98881 12.98312 12.97788 12.97317 12.96906
## [793] 12.96562 12.96226 12.95840 12.95406 12.94931 12.94418 12.93872 12.93298
## [801] 12.92699 12.92081 12.91449 12.90806 12.90158 12.89508 12.88862 12.88224
## [809] 12.87599 12.86991 12.86404 12.85844 12.85314 12.84820 12.84366 12.83957
## [817] 12.83596 12.83289 12.83040 12.82854 12.82736 12.82649 12.82557 12.82462
## [825] 12.82364 12.82265 12.82167 12.82070 12.81978 12.81890 12.81809 12.81736
## [833] 12.81672 12.81619 12.81578 12.81552 12.81540 12.81545 12.81569 12.81612
## [841] 12.81676 12.81763 12.81874 12.82010 12.82173 12.82365 12.82587 12.82828
## [849] 12.83077 12.83334 12.83601 12.83878 12.84165 12.84463 12.84773 12.85095
## [857] 12.85430 12.85778 12.86140 12.86517 12.86909 12.87317 12.87741 12.88183
## [865] 12.88642 12.89119 12.89615 12.90130 12.90666 12.91222 12.91799 12.92398
## [873] 12.93016 12.93655 12.94314 12.94992 12.95689 12.96406 12.97141 12.97895
## [881] 12.98666 12.99455 13.00262 13.01085 13.01926 13.02783 13.03656 13.04544
## [889] 13.05449 13.06368 13.07303 13.08252 13.09215 13.10192 13.11183 13.12187
## [897] 13.13205 13.14235
#assign fits to a vector
both_trendb <- fit_bothb
#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax
#reassign dataframes (just to be safe)
work_bothb <- wrfb_both
#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date
#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
data = smooth_frame_bothb,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb,
'</br> Median Log Copies: ', round(both_trendb, digits = 2)),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(both_yminb, digits = 2)),
name = "",
fillcolor = '#D95F02',
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF B") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfb_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_b
save(p_wrf_b, file = "./plotly_objs/p_wrf_b.rda")
#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A',
span = 0.25, n = 898)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'
fit_bothc
## [1] 12.00073 11.99576 11.99087 11.98606 11.98133 11.97668 11.97210 11.96761
## [9] 11.96319 11.95885 11.95459 11.95042 11.94632 11.94230 11.93836 11.93450
## [17] 11.93072 11.92702 11.92341 11.91987 11.91642 11.91304 11.90975 11.90654
## [25] 11.90342 11.90037 11.89741 11.89453 11.89173 11.88902 11.88639 11.88384
## [33] 11.88138 11.87900 11.87670 11.87449 11.87237 11.87032 11.86837 11.86649
## [41] 11.86471 11.86301 11.86139 11.85986 11.85842 11.85706 11.85579 11.85460
## [49] 11.85350 11.85249 11.85157 11.85073 11.84998 11.84932 11.84875 11.84826
## [57] 11.84786 11.84758 11.84744 11.84744 11.84757 11.84784 11.84824 11.84876
## [65] 11.84941 11.85017 11.85106 11.85206 11.85318 11.85440 11.85574 11.85717
## [73] 11.85871 11.86035 11.86208 11.86390 11.86582 11.86782 11.86991 11.87208
## [81] 11.87432 11.87665 11.87904 11.88151 11.88404 11.88664 11.88930 11.89202
## [89] 11.89479 11.89762 11.90050 11.90343 11.90640 11.90941 11.91246 11.91555
## [97] 11.91867 11.92182 11.92500 11.92820 11.93143 11.93467 11.93793 11.94121
## [105] 11.94449 11.94779 11.95122 11.95490 11.95884 11.96301 11.96741 11.97203
## [113] 11.97685 11.98187 11.98707 11.99245 11.99800 12.00370 12.00954 12.01552
## [121] 12.02162 12.02783 12.03415 12.04056 12.04705 12.05362 12.06024 12.06692
## [129] 12.07363 12.08038 12.08715 12.09392 12.10070 12.10746 12.11420 12.12091
## [137] 12.12758 12.13420 12.14075 12.14723 12.15500 12.16530 12.17788 12.19250
## [145] 12.20894 12.22695 12.24630 12.26676 12.28809 12.31005 12.33240 12.35492
## [153] 12.37737 12.39950 12.42109 12.44190 12.46169 12.48023 12.49728 12.51260
## [161] 12.52597 12.53714 12.54588 12.55366 12.56210 12.57113 12.58070 12.59074
## [169] 12.60119 12.61200 12.62311 12.63446 12.64600 12.65766 12.66938 12.68111
## [177] 12.69278 12.70435 12.71575 12.72692 12.73780 12.74835 12.75848 12.76816
## [185] 12.77732 12.78590 12.79384 12.80109 12.80758 12.81326 12.81808 12.82196
## [193] 12.82485 12.82670 12.82745 12.82703 12.82539 12.82247 12.81761 12.81032
## [201] 12.80076 12.78911 12.77554 12.76024 12.74337 12.72510 12.70563 12.68511
## [209] 12.66372 12.64164 12.61904 12.59610 12.57300 12.54990 12.52698 12.50442
## [217] 12.48238 12.46106 12.44061 12.42122 12.40306 12.38630 12.37112 12.35769
## [225] 12.34432 12.32929 12.31274 12.29482 12.27570 12.25550 12.23439 12.21251
## [233] 12.19002 12.16705 12.14377 12.12032 12.09684 12.07350 12.05044 12.02780
## [241] 12.00574 11.98440 11.96394 11.94451 11.92625 11.90932 11.89385 11.87912
## [249] 11.86428 11.84935 11.83435 11.81929 11.80420 11.78908 11.77396 11.75885
## [257] 11.74378 11.72874 11.71377 11.69889 11.68409 11.66941 11.65487 11.64047
## [265] 11.62623 11.61218 11.59832 11.58468 11.57127 11.55812 11.54522 11.53261
## [273] 11.52030 11.50842 11.49706 11.48620 11.47582 11.46589 11.45640 11.44731
## [281] 11.43860 11.43025 11.42223 11.41453 11.40711 11.39995 11.39303 11.38633
## [289] 11.37981 11.37347 11.36727 11.36118 11.35519 11.34928 11.34341 11.33756
## [297] 11.33172 11.32585 11.31993 11.31394 11.30785 11.30140 11.29435 11.28680
## [305] 11.27881 11.27047 11.26185 11.25303 11.24409 11.23509 11.22613 11.21727
## [313] 11.20859 11.20018 11.19210 11.18443 11.17725 11.17064 11.16467 11.15942
## [321] 11.15496 11.15138 11.14875 11.14715 11.14554 11.14293 11.13941 11.13510
## [329] 11.13012 11.12457 11.11856 11.11220 11.10560 11.09888 11.09214 11.08549
## [337] 11.07905 11.07292 11.06722 11.06205 11.05752 11.05376 11.05086 11.04893
## [345] 11.04809 11.04846 11.05012 11.05321 11.05782 11.06408 11.07234 11.08281
## [353] 11.09533 11.10977 11.12598 11.14380 11.16311 11.18374 11.20555 11.22840
## [361] 11.25214 11.27662 11.30170 11.32723 11.35307 11.37907 11.40507 11.43095
## [369] 11.45655 11.48172 11.50632 11.53020 11.55322 11.57522 11.59608 11.61562
## [377] 11.63372 11.65023 11.66720 11.68661 11.70823 11.73182 11.75711 11.78388
## [385] 11.81187 11.84083 11.87053 11.90072 11.93115 11.96157 11.99175 12.02143
## [393] 12.05037 12.07833 12.10505 12.13030 12.15383 12.17539 12.19474 12.21163
## [401] 12.22582 12.23855 12.25122 12.26380 12.27627 12.28860 12.30078 12.31277
## [409] 12.32456 12.33611 12.34740 12.35842 12.36913 12.37951 12.38954 12.39920
## [417] 12.40845 12.41727 12.42564 12.43354 12.44094 12.44782 12.45415 12.45991
## [425] 12.46508 12.46962 12.47352 12.47649 12.47831 12.47905 12.47879 12.47762
## [433] 12.47562 12.47286 12.46942 12.46540 12.46085 12.45587 12.45054 12.44492
## [441] 12.43912 12.43319 12.42723 12.42131 12.41552 12.40992 12.40461 12.39967
## [449] 12.39516 12.39118 12.38632 12.37927 12.37020 12.35929 12.34672 12.33267
## [457] 12.31733 12.30086 12.28346 12.26530 12.24657 12.22744 12.20809 12.18871
## [465] 12.16947 12.15055 12.13214 12.11442 12.09755 12.08174 12.06715 12.05396
## [473] 12.04236 12.03253 12.02464 12.01888 12.01387 12.00818 12.00187 11.99501
## [481] 11.98768 11.97994 11.97187 11.96354 11.95502 11.94638 11.93769 11.92902
## [489] 11.92045 11.91204 11.90387 11.89601 11.88852 11.88149 11.87497 11.86905
## [497] 11.86379 11.85926 11.85554 11.85269 11.85079 11.84991 11.85012 11.85149
## [505] 11.85453 11.85962 11.86662 11.87538 11.88576 11.89762 11.91082 11.92523
## [513] 11.94069 11.95707 11.97422 11.99201 12.01030 12.02893 12.04778 12.06670
## [521] 12.08555 12.10419 12.12248 12.14027 12.15743 12.17381 12.18928 12.20369
## [529] 12.21690 12.22877 12.23916 12.24792 12.25493 12.26003 12.26444 12.26943
## [537] 12.27496 12.28097 12.28742 12.29426 12.30143 12.30889 12.31659 12.32447
## [545] 12.33250 12.34061 12.34876 12.35690 12.36498 12.37296 12.38077 12.38837
## [553] 12.39572 12.40276 12.40944 12.41571 12.42153 12.42684 12.43160 12.43575
## [561] 12.43925 12.44204 12.44407 12.44531 12.44569 12.44517 12.44369 12.44094
## [569] 12.43670 12.43109 12.42425 12.41630 12.40737 12.39758 12.38705 12.37592
## [577] 12.36431 12.35234 12.34015 12.32786 12.31558 12.30346 12.29162 12.28017
## [585] 12.26926 12.25900 12.24951 12.24094 12.23339 12.22701 12.22011 12.21107
## [593] 12.20007 12.18728 12.17288 12.15706 12.13999 12.12186 12.10283 12.08311
## [601] 12.06285 12.04224 12.02147 12.00071 11.98013 11.95993 11.94028 11.92135
## [609] 11.90334 11.88641 11.87076 11.85655 11.84397 11.83319 11.82440 11.81778
## [617] 11.81222 11.80653 11.80074 11.79490 11.78905 11.78322 11.77745 11.77179
## [625] 11.76627 11.76094 11.75583 11.75098 11.74643 11.74223 11.73841 11.73500
## [633] 11.73206 11.72962 11.72771 11.72639 11.72568 11.72563 11.72628 11.72828
## [641] 11.73216 11.73778 11.74500 11.75370 11.76372 11.77495 11.78723 11.80044
## [649] 11.81443 11.82907 11.84423 11.85977 11.87554 11.89142 11.90727 11.92294
## [657] 11.93831 11.95324 11.96759 11.98123 11.99401 12.00581 12.01648 12.02588
## [665] 12.03389 12.04151 12.04980 12.05870 12.06817 12.07814 12.08856 12.09939
## [673] 12.11055 12.12200 12.13369 12.14556 12.15755 12.16962 12.18170 12.19374
## [681] 12.20569 12.21750 12.22910 12.24044 12.25148 12.26215 12.27240 12.28218
## [689] 12.29143 12.30009 12.30812 12.31546 12.32205 12.32811 12.33388 12.33939
## [697] 12.34465 12.34968 12.35448 12.35908 12.36350 12.36773 12.37181 12.37575
## [705] 12.37955 12.38324 12.38683 12.39034 12.39378 12.39717 12.40051 12.40384
## [713] 12.40715 12.41047 12.41382 12.41719 12.42063 12.42412 12.42771 12.43138
## [721] 12.43517 12.43891 12.44241 12.44571 12.44880 12.45171 12.45444 12.45701
## [729] 12.45942 12.46169 12.46384 12.46588 12.46781 12.46965 12.47141 12.47311
## [737] 12.47476 12.47636 12.47794 12.47950 12.48105 12.48262 12.48420 12.48582
## [745] 12.48743 12.48898 12.49047 12.49190 12.49326 12.49457 12.49581 12.49700
## [753] 12.49811 12.49917 12.50017 12.50110 12.50197 12.50277 12.50351 12.50419
## [761] 12.50480 12.50535 12.50583 12.50625 12.50661 12.50689 12.50712 12.50727
## [769] 12.50736 12.50739 12.50732 12.50716 12.50690 12.50654 12.50611 12.50560
## [777] 12.50502 12.50437 12.50367 12.50292 12.50212 12.50129 12.50043 12.49954
## [785] 12.49864 12.49772 12.49680 12.49589 12.49498 12.49409 12.49322 12.49238
## [793] 12.49157 12.49063 12.48940 12.48789 12.48614 12.48417 12.48199 12.47964
## [801] 12.47714 12.47451 12.47177 12.46895 12.46608 12.46317 12.46025 12.45734
## [809] 12.45448 12.45167 12.44894 12.44633 12.44385 12.44152 12.43937 12.43742
## [817] 12.43570 12.43424 12.43304 12.43214 12.43157 12.43111 12.43058 12.42998
## [825] 12.42932 12.42862 12.42787 12.42709 12.42629 12.42549 12.42468 12.42389
## [833] 12.42312 12.42238 12.42168 12.42103 12.42044 12.41992 12.41948 12.41914
## [841] 12.41890 12.41876 12.41875 12.41887 12.41913 12.41955 12.42012 12.42079
## [849] 12.42146 12.42216 12.42288 12.42363 12.42441 12.42522 12.42607 12.42696
## [857] 12.42789 12.42887 12.42991 12.43100 12.43215 12.43336 12.43464 12.43600
## [865] 12.43742 12.43893 12.44051 12.44219 12.44395 12.44580 12.44776 12.44981
## [873] 12.45195 12.45419 12.45652 12.45894 12.46145 12.46405 12.46672 12.46948
## [881] 12.47232 12.47523 12.47822 12.48128 12.48441 12.48761 12.49088 12.49421
## [889] 12.49760 12.50105 12.50456 12.50813 12.51175 12.51542 12.51914 12.52291
## [897] 12.52673 12.53058
#assign fits to a vector
both_trendc <- fit_bothc
#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax
#reassign dataframes (just to be safe)
work_bothc <- wrfc_both
#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date
#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
data = smooth_frame_bothc,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc,
'</br> Median Log Copies: ', round(both_trendc, digits = 2)),
line = list(color = '#E7298A', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(both_yminc, digits = 2)),
name = "",
fillcolor = '#E7298A',
line = list(color = '#E7298A')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF C") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfc_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#E7298A', size = 6, opacity = 0.65))
p_wrf_c
save(p_wrf_c, file = "./plotly_objs/p_wrf_c.rda")
save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
save(both_ymina, file = "./plotly_objs/both_ymina.rda")
save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")
save(both_yminb, file = "./plotly_objs/both_yminb.rda")
save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")
save(both_yminc, file = "./plotly_objs/both_yminc.rda")
save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")